/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

 /***************************************************************************
 * Name: errors.h
 *
 * Purpose: PandaOS base error code define and helper API implementation.
 *
 * Developer:
 *   wen.gu , 2020-05-11
 *
 * TODO:
 *
 ***************************************************************************/

 /******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __PANDA_CORE_ERRORS_H__
#define __PANDA_CORE_ERRORS_H__


#include "panda/core/types.h"
#include "panda/core/json.h"

namespace panda
{
namespace core
{
/******************************************************************************
 **    MACROS
 ******************************************************************************/

 /******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
 /** error code of panda */
enum class PandaErrc: int32_t
{
    OK = 0,
    Fail = 1,
    BadParameter = 2,
    NoInit = 3,
    Eof = 4,
    NotImplemented = 5,
    NotFound = 6,
    Undefined = 7,
    InvaildName = 8,
    InsufficientResources = 9,
    InvalidStatus = 10,
    OutOfRange = 11,
    UnsupportedType = 12,
    Timeout = 13,
    BadAddress = 14,
    ConnectionAborted = 15, /**< connection aborted(ECONNABORTED) */
    ConnectionAlreadyInProgress = 16, /**< connection already in progress(EALREADY) */
    ConnectionRefused = 17, /**< connection refused(ECONNREFUSED) */
    ConnectionReset = 18, /**< connection reset(ECONNRESET) */
    BadMessage = 19, 
    OperationCanceled = 20, /**< operation canceled(ECANCELED) */
    OperationInProgress = 21, /**< operation in progress(EINPROGRESS) */
    OperationNotPermitted = 22, /**< operation not permitted(EPERM) */
    OperationNotSupported = 23, /**< operation not supported(EOPNOTSUPP) */
    OperationWouldBlock = 24, /**< operation would block(EWOULDBLOCK) */
    OutOfMemory = 25,  
    AlreadyExisted = 26, /**< target already existed */
    ResourceIsBusy = 27, /**< target is busing, */
    Mismatch = 28,       /**< the condition mismatch */

};
 /******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/

CORE_API const char* ErrorStr(PandaErrc errc);

/**
 * json:
 * {
 *    code: xxx,   //Integer
      description: xxx  //string
 * }
 */
CORE_API void Error2Json(PandaErrc err, Value& val);

/**
 * json:
 * {
 *     code: xxx //integer
 * }
 *
 * here just need error code in json value
 */
CORE_API PandaErrc Json2Error(const Value& val);
} /** namespace core*/
} /** namespace panda*/

#endif /** !__PANDA_CORE_ERRORS_H__ */
